import http from "../../utils/Axios/index";

export interface IResUserListData {
  account: string; //账号
  deptId: string; //部门
  id: string; // id
  name: string; //名称
  phone: string; // 电话号码
  realName: string; //真实名称
  roleId: string; //角色
  email: string; // 邮箱
}

const queryUserListService = async () => {
  try {
    const { success, data, msg } = await http<IResUserListData[]>(
      "get",
      "/api/seh-user/user-list",
      {}
    );
    if (success) {
      return data;
    } else {
      throw new Error(msg);
    }
  } catch (e) {
    throw new Error(e);
  }
};

export interface IUserList {
  [key: string]: IResUserListData;
}

export const queryUserListController = async () => {
  const resData = await queryUserListService();
  const userList: IUserList = {};
  if (resData.length) {
    resData.forEach((item) => {
      userList[item.id] = item;
    });
    return userList;
  }
};
